﻿


using Order.Application.Dtos;

namespace Order.API.Endpoints
{
    public class GetOrders : ICarterModule
    {
        public record GetOrdersResponse(PaginatedResult<OrderDto> Orders);
        public record GetOrdersRequest(PaginationRequest pageNavigation);
        public void AddRoutes(IEndpointRouteBuilder app)
        {
            app.MapGet("/orders", async (GetOrdersRequest request,ISender sender) =>
            {
                var command=request.Adapt<GetOrdersQuery>();
                var result=await sender.Send(command);
                var response=result.Adapt<GetOrdersResponse>();
                return Results.Ok(response);
            }).WithName("GetOrders")
        .Produces<GetOrdersResponse>(StatusCodes.Status200OK)
        .ProducesProblem(StatusCodes.Status400BadRequest)
        .ProducesProblem(StatusCodes.Status404NotFound)
        .WithSummary("Get Orders")
        .WithDescription("Get Orders");
        }
    }
}
